<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let arr = [2, 4, 6, 8, 10, 11]
        // let arr = [13, 11]
        // 仿写some, 数组中有一项满足回调函数的条件，则返回true，全都不满足 返回false
        // let res1 = arr.some(function (item, index, arr) {
        //     return item % 2 === 0
        // })
        // console.log(res1)
        // function newSome(arr, fn) {
        //     for (i = 0; i < arr.length; i++) {
        //         if (fn(arr[i], i, arr) === true) {
        //             var a = 0
        //             a = a + 1
        //         }
        //     }
        //     if (a > 0) {
        //         return true
        //     } else {
        //         return false
        //     }
        // }
        // var res = newSome(arr, function (item, index, arr) {
        //     console.log(item, index, arr)
        //     return item % 2 === 0
        // })
        // console.log(res)

        Array.prototype.newSome = function(fn) {
            let a = 0
            for (i = 0; i < this.length; i++) {
                if (fn(this[i], i, this) === true) {
                    a += 1
                }
            }
            if (a > 0) {
                return true
            } else {
                return false
            }
        }
        let res = arr.newSome(function(item, index, arr) {
            console.log(item, index, arr)
            return item % 2 === 0
        })
        console.log(res)



        // 仿写every，数组中每一项都满足回调函数的条件，则返回true，有一项不满足就返回false
        // let res2 = arr.every(function (item, index, arr) {
        //     return item % 2 === 0
        // })
        // console.log(res2)
        let arr1 = [2, 4, 6, 8, 10]
        Array.prototype.newEvery = function(fn) {
            let a = 0
            for (i = 0; i < this.length; i++) {
                if (fn(this[i], i, this) === false) {
                    a += 1
                }
            }
            if (a > 0) {
                return false
            } else {
                return true
            }
        }
        let res1 = arr1.newEvery(function(item, index, arr) {
            console.log(item, index, arr)
            return item % 2 === 0
        })
        console.log(res1)



    </script>
</body>

</html>